<!--
    group: 渠道信息
    name: 寄送合同
    url: /registerProcess/sendingContract
-->
<template>
  <div class="box">
    <!--  主体部分  -->
    <div class="main_content">
      <h3>寄送合同</h3>
      <a-divider />

      <div class="box_item">
        <div class="item">
          <h4>合同寄送地址</h4>
          <p>
            寄送地址：湖北省荆州市沙市区义乌小商品城二期2栋4楼中雄公司 <br>
            收件人：杨昌燕 <br>
            联系电话：13707215941
          </p>
          <a-button class="line" @click="copyOnekey">一键复制</a-button>
        </div>
        <div class="item">
          <a-form-model
            ref="ruleForm"
            :model="form"
            :rules="rules"
            :label-col="labelCol"
            :wrapper-col="wrapperCol"
          >
            <a-form-model-item label="物流公司" prop="mailEnt">
              <a-select v-model="form.mailEnt" placeholder="请选择">
                <a-select-option v-for="(item,index) in logistics" :key="index" :value="item.keyValue">{{ item.keyValue }}</a-select-option>
              </a-select>
            </a-form-model-item>
            <a-form-model-item label="快递单号" prop="mailNo">
              <a-input v-model="form.mailNo" placeholder="请输入" type="text" />
            </a-form-model-item>
            <a-form-model-item label="寄件人联系电话" prop="phone">
              <a-input v-model="form.phone" type="text" placeholder="请输入" />
            </a-form-model-item>
            <a-form-model-item :wrapper-col="{ span: 16, offset: 8 }">
              <div class="footer">
                <a-button class="btnsLarge" type="primary" @click="sendContract">提交寄送信息</a-button>
                <a v-if="sign == 1" @click="back(1)">返回</a>
                <a v-else @click="back">返回首页</a>
              </div>
            </a-form-model-item>
          </a-form-model>
        </div>

      </div>

    </div>
  </div>
</template>

<script>
import { getPayMethodList } from '../../common/interfaceData'
import { getContractAgree } from '../../api/enterprise'
export default {
  name: "sendingContract",
  data(){
    return{
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
      form: {},
      rules: {
        mailNo: [{required: true, message: '请输入物流单号',trigger: "blur"}],
        mailEnt: [{required: true, message: '请选择物流公司',trigger: "change"}],
        phone: [
          {required: true, message: '请输入联系电话',trigger: "blur"},
          { validator: this.validatePhone }
        ],
      },
      timer: null,
      logistics: [],  //快递公司列表
      proessId: null,

      sign: null,  //来源  ''-首页  1合同列表
    }
  },
  created() {
    getPayMethodList('3000000001','/industryinfo/all',this);

    this.proessId = this.$route.query.zxyAgreeId;
    this.sign = this.$route.query.sign;
  },
  methods: {
    //一键复制
    copyOnekey(){
      var oInput = document.createElement("input"); //创建隐形input
      oInput.value = '寄送地址：湖北省荆州市沙市区义乌小商品城二期2栋4楼中雄公司'; //
      // oInput.value = '寄送地址：湖北省荆州市沙市区义乌小商品城二期2栋4楼中雄公司 \n 收件人：杨昌燕 \n联系电话：13707215941'
      document.body.appendChild(oInput);
      oInput.select();
      document.execCommand("Copy");
      oInput.remove();
      this.$message.success('复制成功');
    },
    //提交寄送信息
    sendContract(){
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          let params = {};
          params = this.form;
          params.agreeInfoId = this.proessId;   //合同主键
          params.transCode = 30012;    //动作类型：3001合同创建、30011合同下载、30012合同邮寄、30013合同上传、3002合同签署
          getContractAgree(params).then(res => {
            if (res.success){
              this.$message.success(res.result);

              // 将定时器名字赋值到变量中
              this.timer = setInterval(() => {
                if (this.sign == 1){
                  this.$router.push({
                    path: '/infoManagement/infoManagementDetails',
                    query: {
                      pagetab: 6   //跳转我的合同页签
                    }
                  })
                }else {
                  this.$router.push({
                    path: '/index/index'
                  })
                }
              }, 1000);


            }else {
              this.$message.warning(res.message);
            }
          })
        } else {
          return false;
        }
      });
    },
    //返回
    back(type){
      if (type == 1){
        this.$router.back();
      }else{
        this.$router.push({
          path: '/index/index'
        })
      }
    },
    // 校验手机号
    validatePhone(rule,value,callback){
      let reg = /^(1\d{10})$/;
      if (!value || reg.test(value)){
        callback();
      }else{
        callback("您的手机号码格式不正确!");
      }
    },
  }
}
</script>

<style scoped lang="less">
h3{
  font-size: 30px;
}
.box{
  width: 100%;
  background: @color-white;
  padding: 0 10%;
}
.box_item{
  width: 100%;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}

.item{
  width: 60%;
  margin-bottom: 30px;
}

h4{
  font-weight: bolder;
  font-size: 20px;
}
a{
  text-decoration: underline;
  margin-left: 10px;
  white-space: nowrap;
}
p{
  color: @color-black;
  line-height: 30px;
}

.footer{
  margin-top: 20px;
  display: flex;
  align-items: flex-end;
}

</style>
